import React from 'react';
import UploadFile from '@/components/FileUpload';
import { CategorySelect } from '@/components/Category';
import ArticleEditor from '../../../../components/ArticleEditor';
import { galleryRule } from '../service';


const galleryProps = {
    length: 4,
    onRemove: (file: any) => {
        galleryRule(file.id);
    },
};

export const createFields = [
    {
        key: 'name',
        name: '商品名称',
        type: 'input',
        required: true
    },
    {
        key: 'nick',
        name: '宝贝昵称',
        type: 'input'
    },
    {
        key: 'category_id',
        name: '分类',
        render: (it: any) => <CategorySelect placeholder={`请输入${it.name}`} />,
        required: true
    },
    {
        key: 'brief',
        name: '简介',
        type: 'textarea'
    },
    {
        key: 'main_pic',
        name: '主图',
        render: (it: any, data: any) =>　{
            console.log(data, 'data')
            return <UploadFile fileName={[{ url: data.main_pic, name: data.main_pic }]} />;
        },
        required: true
    },
    {
        key: 'banner',
        name: '轮播图',
        render: (it: any, data: any) => <UploadFile {...galleryProps} fileName={data.banner} />,
        required: true
    },
    {
        key: 'desc',
        name: '商品描述',
        render: (it: any, data: any) => <ArticleEditor basic={['text', 'image', 'title']} />,
        required: true
    },
];


export const priceFields = [
    {
        key: 'stock',
        name: '库存',
        type: 'inputNumber',
    },
    {
        key: 'cost_price',
        name: '成本价',
        type: 'inputNumber',
    },
    {
        key: 'market_price',
        name: '原价(划线价)',
        type: 'inputNumber',
        required: true
    },
    {
        key: 'price',
        name: '销售价',
        type: 'inputNumber',
        required: true
    },
]